package practice;

/**
 * @author ：wangchao
 * @version ：V1.0
 * @program ：MySpringCloud
 * @date ：Created in 2020/10/10 11:34
 * @description ：数组转二叉树
 */
public class ArrayConvertTree {
    class TreeNode {
        int value;
        TreeNode left;
        TreeNode right;

        TreeNode(int val) {
            value = val;
        }
    }

    public TreeNode createTreeByArray(Integer[] arr, int index) {
        TreeNode treeNode = null;
        if (index < arr.length) {
            if (arr[index] == null) {
                return null;
            }
            treeNode = new TreeNode(arr[index]);
            treeNode.left = createTreeByArray(arr, 2 * index + 1);
            treeNode.right = createTreeByArray(arr, 2 * index + 2);
            return treeNode;
        }
        return null;
    }
}